
package com.shop.cloud.mall.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.cloud.common.core.util.R;
import com.shop.cloud.common.log.annotation.SysLog;
import com.shop.cloud.mall.common.entity.GoodsCategoryShop;
import com.shop.cloud.mall.admin.service.GoodsCategoryShopService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 店铺商品分类表
 *
 * @author
 * @date 2020-08-26 08:58:11
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/goodscategoryshop")
@Tag(description = "goodscategoryshop", name = "店铺商品分类表管理")
public class GoodsCategoryShopController {

    private final GoodsCategoryShopService goodsCategoryShopService;

    /**
     * 分页列表
     * @param page 分页对象
     * @param goodsCategoryShop 店铺商品分类表
     * @return
     */
    @Operation(summary = "分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ato.hasAuthority('mall:goodscategoryshop:index')")
    public R getPage(Page page, GoodsCategoryShop goodsCategoryShop) {
        return R.ok(goodsCategoryShopService.page(page, Wrappers.query(goodsCategoryShop)));
    }

	/**
	 *  返回树形集合
	 * @return
	 */
	@Operation(summary = "返回树形集合")
	@GetMapping("/tree")
	public R getTree(GoodsCategoryShop goodsCategoryShop) {
		return R.ok(goodsCategoryShopService.selectTree(goodsCategoryShop));
	}

    /**
     * 店铺商品分类表查询
     * @param id
     * @return R
     */
    @Operation(summary = "店铺商品分类表查询")
    @GetMapping("/{id}")
    @PreAuthorize("@ato.hasAuthority('mall:goodscategoryshop:get')")
    public R getById(@PathVariable("id") String id) {
        return R.ok(goodsCategoryShopService.getById(id));
    }

    /**
     * 店铺商品分类表新增
     * @param goodsCategoryShop 店铺商品分类表
     * @return R
     */
    @Operation(summary = "店铺商品分类表新增")
    @SysLog("新增店铺商品分类表")
    @PostMapping
    @PreAuthorize("@ato.hasAuthority('mall:goodscategoryshop:add')")
    public R save(@RequestBody GoodsCategoryShop goodsCategoryShop) {
        return R.ok(goodsCategoryShopService.save(goodsCategoryShop));
    }

    /**
     * 店铺商品分类表修改
     * @param goodsCategoryShop 店铺商品分类表
     * @return R
     */
    @Operation(summary = "店铺商品分类表修改")
    @SysLog("修改店铺商品分类表")
    @PutMapping
    @PreAuthorize("@ato.hasAuthority('mall:goodscategoryshop:edit')")
    public R updateById(@RequestBody GoodsCategoryShop goodsCategoryShop) {
        return R.ok(goodsCategoryShopService.updateById(goodsCategoryShop));
    }

    /**
     * 店铺商品分类表删除
     * @param id
     * @return R
     */
    @Operation(summary = "店铺商品分类表删除")
    @SysLog("删除店铺商品分类表")
    @DeleteMapping("/{id}")
    @PreAuthorize("@ato.hasAuthority('mall:goodscategoryshop:del')")
    public R removeById(@PathVariable String id) {
        return R.ok(goodsCategoryShopService.removeById(id));
    }

}
